<html>
<head><meta charset="utf-8"><title>Adding feature to &quot;toggle&quot; lifetimes on / off · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Adding.20feature.20to.20.22toggle.22.20lifetimes.20on.20.2F.20off.html">Adding feature to &quot;toggle&quot; lifetimes on / off</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="224946225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Adding%20feature%20to%20%22toggle%22%20lifetimes%20on%20/%20off/near/224946225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Colin Kirkpatrick <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Adding.20feature.20to.20.22toggle.22.20lifetimes.20on.20.2F.20off.html#224946225">(Feb 02 2021 at 22:25)</a>:</h4>
<p>Hello, I'm looking into adding a feature to the flatbuffers library here - <a href="https://github.com/google/flatbuffers">https://github.com/google/flatbuffers</a>. </p>
<p>I'm trying to make it so you can (via cfg features) add support for the <code>bytes</code> crate. This means taking many implementations that currently specify lifetimes and creating very similar ones without said lifetimes.</p>
<p>Does anyone know of some macro / technique that could be used to shorten this process / keep the code a bit cleaner and maintainable?</p>
<p>For context: flatbuffers currently passes around <code>u8</code> arrays with lifetimes specified, I'd like to add a feature that would allow a user to use <code>Bytes</code> / <code>BytesMut</code> instead (which have no explicit lifetimes).</p>



<a name="224949255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Adding%20feature%20to%20%22toggle%22%20lifetimes%20on%20/%20off/near/224949255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Adding.20feature.20to.20.22toggle.22.20lifetimes.20on.20.2F.20off.html#224949255">(Feb 02 2021 at 22:54)</a>:</h4>
<p>As rather a hack, <code>type Foo&lt;'a&gt; = i32;</code> is legal, so you might be able to just keep the lifetimes in the code you write and have users not care.</p>



<a name="224949305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Adding%20feature%20to%20%22toggle%22%20lifetimes%20on%20/%20off/near/224949305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Adding.20feature.20to.20.22toggle.22.20lifetimes.20on.20.2F.20off.html#224949305">(Feb 02 2021 at 22:55)</a>:</h4>
<p>But also, features are supposed to be additive, so I'm not sure what you're looking for here.</p>



<a name="224949356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Adding%20feature%20to%20%22toggle%22%20lifetimes%20on%20/%20off/near/224949356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Adding.20feature.20to.20.22toggle.22.20lifetimes.20on.20.2F.20off.html#224949356">(Feb 02 2021 at 22:55)</a>:</h4>
<p>Maybe you can just deal in <code>impl Foo&lt;'a&gt;</code>, where the <code>Bytes</code> versions don't use the lifetime in their associated types?</p>



<a name="224950875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Adding%20feature%20to%20%22toggle%22%20lifetimes%20on%20/%20off/near/224950875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Colin Kirkpatrick <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Adding.20feature.20to.20.22toggle.22.20lifetimes.20on.20.2F.20off.html#224950875">(Feb 02 2021 at 23:10)</a>:</h4>
<p>The problem there is you'll still have compilation issues when trying to send flexbuffers across channels. I suppose you could just put a <code>'static</code> lifetime in though... still not sure. I'll have to ask what the maintainers are comfortable with. </p>
<p>Personally I'd rather just stick with a pure bytes implementation, particularly with how my current research is going. Would be a breaking change though :/.</p>



<a name="225098200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Adding%20feature%20to%20%22toggle%22%20lifetimes%20on%20/%20off/near/225098200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Colin Kirkpatrick <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Adding.20feature.20to.20.22toggle.22.20lifetimes.20on.20.2F.20off.html#225098200">(Feb 03 2021 at 23:22)</a>:</h4>
<p>So after a bit of tinkering I've found a solution that'll work. </p>
<p>So I've figured out a way to do the generic approach. Basically there'll be a trait bound on a generic type and I can just add different types of buffer implementations by implementing the overall <code>Buffer</code> interface. </p>
<p>Not sure why I didn't think of that before lol. Thanks for the help though!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>